package com.linln.admin.member.controller;

import com.linln.modules.system.domain.Area;
import com.linln.modules.system.service.AreaService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.linln.modules.member.domain.MemberOrder;
import com.linln.modules.member.service.MemberOrderService;

import java.util.List;

/**
 * @author hct
 * @date 2019/09/12
 */
@Controller
@RequestMapping("/member/order")
public class MemberOrderController {

    @Autowired
    private MemberOrderService memberOrderService;

    @Autowired
    private AreaService areaService;

    /**
     * 列表页面
     */
    @GetMapping("/index")
    @RequiresPermissions("member:order:index")
    public String index(Model model, MemberOrder MemberOrder) {

        // 创建匹配器，进行动态查询匹配
        ExampleMatcher matcher = ExampleMatcher.matching();

        // 获取数据列表
        Example<MemberOrder> example = Example.of(MemberOrder, matcher);
        Page<MemberOrder> list = memberOrderService.getPageList(example);
        List<MemberOrder> content = list.getContent();
        for (MemberOrder aa :content
        ) {
            if(aa==null) continue;
            Area area = areaService.findByCode(aa.getArea());
            if(area != null){
                Area parea = areaService.getById(area.getPid());
                aa.setAreaName(area.getName());
                if(parea != null){
                    aa.setAreaName(parea.getName()+area.getName());
                }
            }
        }
        // 封装数据
        model.addAttribute("list", content);
        model.addAttribute("page", list);
        return "/member/order/index";
    }

     

    /**
     * 跳转到详细页面
     */
    @GetMapping("/detail/{id}")
    @RequiresPermissions("member:MemberOrder:detail")
    public String toDetail(@PathVariable("id") MemberOrder memberOrder, Model model) {
        model.addAttribute("order",memberOrder);
        return "/member/order/detail";
    }

     
}